package OOP;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ReflectDemo {
    public int a;
    private int b;

    public static void main(String[] args) {
        Class<ReflectDemo> reflectDemoClass = ReflectDemo.class;
        // get all fields
        for (Field declaredField : reflectDemoClass.getDeclaredFields()) {
            System.out.println(
                    "field: " + declaredField.getName() + ", modifier: "
                            + Modifier.toString(declaredField.getModifiers()));
        }
        // get all public fields
        for (Field field : reflectDemoClass.getFields()) {
            System.out.println(
                    "public field: " + field.getName() + ", modifier: " + Modifier.toString(field.getModifiers()));
        }
        // get all methods
        for (Method declaredMethod : reflectDemoClass.getDeclaredMethods()) {
            System.out.println(
                    "method: " + declaredMethod.getName() + ", modifier: "
                            + Modifier.toString(declaredMethod.getModifiers()));
        }
    }

    public void fun1() {
    }

    private void fun2() {
    }
}
